﻿using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Controls.Primitives;
using EDMDesigner.Designer.Controls.Util;
using System.Windows;
using System.Windows.Automation.Peers;

namespace EDMDesigner.Designer.Controls
{
    public class Expander : System.Windows.Controls.Expander
    {
        protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseLeftButtonDown(e);
            if (VisualTreeHelperUtil.GetControlAscendant<TextBox>(e.OriginalSource) == null || VisualTreeHelperUtil.GetControlAscendant<EditableTextBlock>(e.OriginalSource) == null)
            {
                FrameworkElement control = (FrameworkElement)e.OriginalSource;
                while ((control = VisualTreeHelperUtil.GetControlAscendant<StackPanel>(control)) != null)
                    if (control.Name == "HeaderStackPanel")
                    {
                        ClickOnTheHeader();
                        break;
                    }
            }
        }

        protected virtual void ClickOnTheHeader()
        {
        }
    }
}
